package com.spark.lola.controller;

import com.spark.lola.request.RegisterCodeRequest;
import com.spark.lola.request.RegisterRequest;
import com.spark.lola.service.sup.IAccountInfoService;
import com.spark.lola.support.common.util.ResponseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: DengYeJun
 * @Date: 2020/5/7 13:22
 */
@RestController
@RequestMapping(value = "/api/register", produces = "application/json;charset=utf-8")
@Api(value = "/api/register", tags = "注册相关")
public class RegisterController {
    private static final Logger logger = LoggerFactory.getLogger(RegisterController.class);
    @Autowired
    private IAccountInfoService accountInfoService;

    /**
     * 注册
     */
    @ApiOperation(value = "注册")
    @RequestMapping(value = "/",method = RequestMethod.POST)
    @Transactional(rollbackFor = Exception.class)
    public ResponseBean index(@RequestBody RegisterRequest request) throws Exception {
        accountInfoService.register(request);
        return ResponseBean.success();
    }

    /**
     * 获取注册验证码
     */
    @ApiOperation(value = "获取注册验证码")
    @RequestMapping(value = "/code",method = RequestMethod.POST)
    @Transactional(rollbackFor = Exception.class)
    public ResponseBean code(@RequestBody RegisterCodeRequest request) throws Exception {
        accountInfoService.registerCode(request.getUsername(), request.getMobile());
        return ResponseBean.success();
    }
}
